package cn.yunhe.dao.impl;

import java.util.List;
import java.util.Map;

import org.apache.ibatis.session.SqlSession;
import org.springframework.stereotype.Repository;

import cn.yunhe.dao.GoodsDao;
import cn.yunhe.entity.Goods;
import cn.yunhe.util.MybatisHelper;
@Repository
public class GoodsDaoImpl implements GoodsDao{

	@Override
	public List<Goods> getAll() {
		SqlSession session = null;
		session = MybatisHelper.getSession();
		List<Goods> glist = session.selectList("cn.yunhe.dao.GoodsDao.getAll");
		MybatisHelper.closeSession();
		return glist;
	}

	@Override
	public int getCount() {
		SqlSession session = null;
		session = MybatisHelper.getSession();
		int count = session.selectOne("cn.yunhe.dao.GoodsDao.getCount");
		MybatisHelper.closeSession();
		return count;
	}

	@Override
	public List<Goods> getPageList(Map<String,Object> map) {
		SqlSession session = null;
		session = MybatisHelper.getSession();	
		List<Goods> glist = session.selectList("cn.yunhe.dao.GoodsDao.getPageList",map);
		MybatisHelper.closeSession();
		return glist;
	}

	@Override
	public int deleteGoods(int gid) {
		SqlSession session = null;
		session = MybatisHelper.getSession();
		int result = session.delete("cn.yunhe.dao.GoodsDao.deleteGoods", gid);
		session.commit();
		MybatisHelper.closeSession();
		return result;
	}

	@Override
	public int addGoods(Goods goods) {
		SqlSession session = null;
		session = MybatisHelper.getSession();
		int result = session.delete("cn.yunhe.dao.GoodsDao.addGoods", goods);
		session.commit();
		MybatisHelper.closeSession();
		return result;
	}

	@Override
	public int editGoods1(Goods goods) {
		SqlSession session = null;
		session = MybatisHelper.getSession();
		int result = session.delete("cn.yunhe.dao.GoodsDao.editGoods1", goods);
		session.commit();
		MybatisHelper.closeSession();
		return result;
	}

	@Override
	public int editGoods2(Goods goods) {
		SqlSession session = null;
		session = MybatisHelper.getSession();
		int result = session.delete("cn.yunhe.dao.GoodsDao.editGoods2", goods);
		session.commit();
		MybatisHelper.closeSession();
		return result;
	}
	

}
